package cn.myeasyai.controller;

import cn.myeasyai.dto.UserDTO;
import cn.myeasyai.service.FaceService;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Collections;
import java.util.List;

/**
 * @author fushoujiang
 */
@RequestMapping("/face")
@RestController
@CrossOrigin
public class FaceController {
    private static final  Logger LOGGER = LoggerFactory.getLogger(FaceController.class);
    @Resource
    private FaceService faceService;

    @PostMapping("/faceInit")
    public UserDTO faceInit( MultipartFile file, UserDTO userDTO) {
        try {

            return faceService.faceInit(file.getInputStream(), userDTO);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return userDTO;
    }
    @PostMapping("/faceSearch")
    public List<UserDTO> faceSearch( MultipartFile file) {
        try {
            final List<UserDTO> userDTOS = faceService.faceSearch(file.getInputStream());
            LOGGER.info("faceSearch:{}" , JSON.toJSONString(userDTOS));
            return userDTOS;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return Collections.emptyList();
    }

}
